
layui.define(['jquery', 'element', 'layer'], function (e) {
	var $ = layui.jquery,
		layer = layui.layer;
	
	var page = {
		init: function(){
			page.initDom();
			page.event(); // 事件
			page.mapShadow(); // 阴影地图
			page.mapPositioning(); // 定位地图
			page.migrateChart(); // 迁徙图
			page.companyLine(); //从业单位
			page.operators(); // 当日作业人员
		},
		initDom: function() {
			// 改变中心图的大小
			var _m = 100;
			var _h = $(".bigData-main").height()+_m;
			$(".map-box").css({"height": _h+"px", "margin-top": -_m/2+"px"});
			
			/*$(window).resize(function() {
				var _h = $(".bigData-main").height();
				$(".map-box").css("height", _h+"px");
			});*/
			layer.photos({
			  photos: '#layer-photos-demo'
			  ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
			}); 
		},
		event: function() {
			// 切换筛选项
			$("body").on("click", ".filter-item-box .filter-item", function(e){
	    		$(this).addClass("current").siblings().removeClass("current");
	    	});
	    	
	    	// 图片文字提示
	    	$(".scenePicture-describe").on("click", function() {
	    		layer.tips('图片详情描述', '.scenePicture-describe', {
				  tips: [1, '#3595CC'],
				  time: 4000
				});
	    	});
		},
		companyLine: function(){
			
			 $.ajax({
			     type:"post",
			     url:"dateArray",
			     data:{},
			     dataType:"json",
			     success:function (data) {
			    	
			    	 var dateList = data;
			    	 var xAxisData = [];
			    	 var gcjs = [];
			    	 var bpy = [];
			    	 var aqy = [];
			    	 var bgy = [];
			    	 for(var i=0; i<dateList.length; i++) {
			    		 xAxisData.push(dateList[i].date); 
			    		 gcjs.push(dateList[i].gcjs); 
			    		 bpy.push(dateList[i].bpy); 
			    		 aqy.push(dateList[i].aqy); 
			    		 bgy.push(dateList[i].bgy); 
			    	 }
			    	 
			    	 var ojb01 = {
				        	symbol: "none", 
				            name: '工程技术人员',
				            data: gcjs,
				            type: 'line',
				            stack: '总量',
				            smooth: false
			            };
			    	 
			    	 var ojb02 = {
					        	symbol: "none", 
					            name: '爆破员',
					            data: bpy,
					            type: 'line',
					            stack: '总量',
					            smooth: false
				            };
			    	 
			    	 var ojb03 = {
					        	symbol: "none", 
					            name: '安全员',
					            data: aqy,
					            type: 'line',
					            stack: '总量',
					            smooth: false
				            };
			    	 
			    	 var ojb04 = {
					        	symbol: "none", 
					            name: '保管员',
					            data: bgy,
					            type: 'line',
					            stack: '总量',
					            smooth: false
				            };
			    	 
			    	 	var color = ['#e2e408','#fb4581','#36e3ef','#33fc50'];
						var legendData = ['工程技术人员','爆破员','安全员','保管员'];
					
						var option = {
							textStyle: {
								color: "#fff"
							},
						    color: color,
						    tooltip : {
						        trigger: 'axis',//item
						        axisPointer: {
						            type: 'cross',
						            label: {
						                backgroundColor: '#6a7985'
						            }
						        }
						    },
						    legend: {
						    	top: 5,
						    	left: 5,
						    	textStyle: {
						    		color: "#fff"
						    	},
						        data: legendData
						    },
						    grid: {
						    	top: 50,
						    	height: 90
						    },
						    xAxis: {
						        type: 'category',
						        name: "月",
						        nameTextStyle: {
						            color: "#fff",
						            align: "left"
						        },
						        boundaryGap: true, // 坐标轴两边留白策略，类目轴和非类目轴的设置和表现不一样。
						        axisLine: {
						        	lineStyle: {
						        		color: "#fff"
						        	}
						        },
						        axisTick: {
						        	show: false // 是否显示坐标轴刻度。
						        },
						        data: xAxisData
						    },
						    yAxis: {
						        name: "人",
						        nameTextStyle: {
						            color: "#fff"
						        },
						        axisLine: {
						        	lineStyle: {
						        		color: "#fff"
						        	}
						        },
						        axisTick: {
						        	show: false // 是否显示坐标轴刻度。
						        },
						        splitLine: {
						        	show: true,
						        	lineStyle: {
						        		color: "rgba(255, 255, 255, .3)"
						        	}
						        },
						        min: 0
						    },
						    series: [ojb01,ojb02,ojb03,ojb04]
						};
						var chart = echarts.init(document.getElementById('employmentUnit'));
						chart.setOption(option);
			    	 
			     }
			 });
		},
		// 作业单位
		operators: function() {
			 $.ajax({
			     type:"post",
			     url:"addressArray",
			     data:{},
			     dataType:"json",
			     success:function (data) {
				// 定位
				var myChart = echarts.init(document.getElementById('operators_map'));
				var color = ['#428bf9','#f2ff00b0','#52d8a1'];
				var legendData = ['建设单位','施工单位','监理单位'];
				var xAxisData = data;//['凯里市', '麻江县', '天柱县','镇远县','岑巩县','施秉县','黄平县','台江县','三穗县','剑河县','锦屏县','丹寨县','雷山县','榕江县','黎平县','从江县'];
				var seriesLabel = {
				    normal: {
				        show: false, // 是否显示数量
				        textBorderColor: '#fff', // 阴影颜色
				        textBorderWidth: 2 // 阴影宽度
				    }
				}
				
				/* 数据 */
				var obj;
				 $.ajax({
 				     type:"post",
 				   	 async:false,
 				     url:"unitByAddressBytype",//?areaId="+xAxisData+""
 				     data:{},
 				     dataType:"json",
 				     success:function (num) {
 				    	obj=num;
 				     }
 				 });
				option = {
				    /*title: {
				        text: 'Wheater Statistics'
				    },*/
					textStyle: {
						color: "#fff"
					},
				    color: color,
				    tooltip: {
				        trigger: 'axis',
				        axisPointer: {
				            type: 'shadow'
				        }
				    },
				    legend: {
				    	top: 10,
				    	left: 40,
				    	textStyle: {
				    		color: "#fff"
				    	},
				        data: legendData
				    },
				    grid: {
				    	top: 33,
				    	left: 43,
				    	height: 100
				    },
				    xAxis: {
				        type: 'value',
				        name: '家',
				        axisLabel: {
				            formatter: '{value}'
				        },
				        nameTextStyle: {
				            color: "#fff"
				        },
				        axisTick: {
				        	show: false // 是否显示坐标轴刻度。
				        },
				        axisLine: {
				        	lineStyle: {
				        		color: "#fff"
				        	}
				        },
				        splitLine: {
				        	show: true,
				        	lineStyle: {
				        		color: "rgba(255, 255, 255, .3)"
				        	}
				        }
				    },
				    yAxis: {
				        type: 'category',
				        nameTextStyle: {
				            color: "#fff"
				        },
				        axisLine: {
				        	lineStyle: {
				        		color: "#fff"
				        	}
				        },
				        axisTick: {
				        	show: true // 是否显示坐标轴刻度。
				        },
				        //inverse: true,
				        data: xAxisData
				    },
				    dataZoom: [
			            
			            {
			                show: true,
			                yAxisIndex: 0,
			               
			                height: '45%',
			                left: '93%',
			                end: 20
			            }
			        ],
	
				    series: [
				        {
				            name: '建设单位',
				            type: 'bar',
				            label: seriesLabel,
				            data: obj[0]
				        },
				        {
				            name: '施工单位',
				            type: 'bar',
				            label: seriesLabel,
				            data: obj[1]
				        },
				        {
				            name: '监理单位',
				            type: 'bar',
				            label: seriesLabel,
				            data: obj[2]
				        }
				    ]
				};
			     
				myChart.setOption(option);
			     }
			 });
		},
		// 定位图
		mapShadow: function() {
			var qiandongnan = ctx + "/assets/blastStatistics/templates/layer-master/json/guizhou/qiandongnan.json";
			$.get(qiandongnan, function(mapJson) {
				var mapName = "qiandongnan";
				echarts.registerMap(mapName, mapJson);
				
				// 定位
				var shadow_map = echarts.init(document.getElementById('shadow_map'));
				
				shadowOption = {
				    geo: {
				        map: mapName,
				        roam: false,
				    	itemStyle: {
				        	normal: {
				            	areaColor:  '#0000008c',
				                borderWidth: 5,
				                borderColor:'#00ffff',
				                shadowColor: '#00ffff',//第一张地图秒阔颜色
				                shadowBlur: 60
				            },
				            emphasis: {
				                areaColor: '#ff0e0e00'
				            }
				    	}
				    }
				};
				shadow_map.setOption(shadowOption);
			});
		},
		migrateChart: function() {
			var qiandongnan = ctx + "/assets/blastStatistics/templates/layer-master/json/guizhou/qiandongnan.json";
			$.get(qiandongnan, function(mapJson) {
				var mapName = "qiandongnan";
				echarts.registerMap(mapName, mapJson);
				var data = [
				    {name: '黎平机场', value: 9},
				    {name: '凯里学院', value: 12},
				    {name: '西江千户苗寨', value: 12},
				    {name: '舞阳河', value: 12}
				];
				// 经纬度
				var geoCoordMap = {
					'凯里市': [107.97, 26.58],
					'黎平机场': [109.161125, 26.32655], // 黎平机场
				  	'凯里学院': [107.89861, 26.531537], // 凯里学院
				  	'西江千户苗寨': [108.179169, 26.499467], // 西江千户苗寨
				    '舞阳河': [108.328647, 27.0465], // 舞阳河
				    '天柱县': [109.178318, 26.929808], // 天柱县
				    '三穗县': [108.685898,26.929824], // 三穗县
				    '榕江县': [108.311176,26.002138], // 榕江县
				    '从江县': [108.921655,25.856663], // 从江县
				    '施秉县': [108.148967,27.216556] // 施秉县
				};
				// 迁徙数据 散开
				/*var migrateData = [
				    [{name:'凯里市'}, {name:'黎平机场',value:95}],
				    [{name:'凯里市'}, {name:'凯里学院',value:90}],
				    [{name:'凯里市'}, {name:'西江千户苗寨',value:80}],
				    [{name:'凯里市'}, {name:'舞阳河',value:70}],
				    [{name:'凯里市'}, {name:'天柱县',value:70}]
				];
				*/
				
				// 迁徙数据  集中
				var migrateData = [
				    [ {name:'黎平机场'},{name:'凯里市',value:95}],
				    [ {name:'黎平机场'},{name:'黎平机场',value:95}],
				    [ {name:'舞阳河'},{name:'凯里市',value:95}],
				    [ {name:'凯里学院'},{name:'凯里市',value:90}],
				    [ {name:'西江千户苗寨'},{name:'凯里市',value:80}],
				    [ {name:'天柱县'},{name:'凯里市',value:70}],
				    [ {name:'榕江县'},{name:'榕江县',value:70}],
				    [ {name:'三穗县'},{name:'三穗县',value:70}],
				    [ {name:'从江县'},{name:'从江县',value:70}],
				    [ {name:'施秉县'},{name:'施秉县',value:70}],
				];
				
				// 迁徙图
				var migrateMap =  echarts.init(document.getElementById('migrateMap'));
				
				var converTmigrateData = function(data) {
					var res = [];
					for(var i = 0; i < data.length; i++) {
						var dataItem = data[i];
						var fromCoord = geoCoordMap[dataItem[0].name];
						var toCoord = geoCoordMap[dataItem[1].name];
						if(fromCoord && toCoord) {
							res.push([{
								coord: fromCoord
							}, {
								coord: toCoord
							}]);
						}
					}
					return res;
				};
				
				var series = [];
				[['凯里市', migrateData]].forEach(function(item, i) {
					series.push({
						name: item[0],
						type: 'lines',
						zlevel: 1,
						effect: {
							show: true,
							period: 6,
							trailLength: 0.7,
							color: '#08ffff',//跟随路线浅蓝色
							symbolSize: 3
						},
						lineStyle: {
							normal: {
							//	color: "#ff0052",
								width: 0,
								curveness: 0.2
							}
						},
						data: converTmigrateData(item[1])
					}, {
						name: item[0],
						type: 'lines',
						zlevel: 2,
						effect: {
							show: true,
							period: 6,
							trailLength: 0,
							symbolSize: 6,
							symbolRadius:10
						},
						lineStyle: {
							normal: {
								color: "#00e7ff",//轨迹颜色绿色
								width: 1,//轨迹线粗细
								opacity: 0.4,
								curveness: 0.2
								
							}
						},
						data: converTmigrateData(item[1])
					}, {
						name: item[0],
						type: 'effectScatter',
						coordinateSystem: 'geo',
						zlevel: 2,
						rippleEffect: {
							brushType: 'stroke'
						},
						label: {
							normal: {
								show: true,
								position: 'right',
								formatter: '{b}'
							}
						},
						symbolSize: function(val) {
							return val[2] / 8;
						},
						itemStyle: {
							normal: {
								color: "#f90808" //集中信息中心字体颜色
							}
						},
						data: item[1].map(function(dataItem) {
							return {
								name: dataItem[1].name,
								value: geoCoordMap[dataItem[1].name].concat([dataItem[1].value])
							};
						})
					});
				});
				
				tmigrateOption = {
					geo: {
						map: mapName,
						label: {
							normal: {
			                    show: true,
			                    textStyle: {
			                        color: '#fff',//各个省字体颜色
			                        fontSize:8
			                    }
			                },
							emphasis: {
								show: false,
								textStyle: {
			                        color: '#ff0101', //各个省鼠标移上去字体颜色
			                        fontSize:14
			                    }
							}
						},
						roam: false,
						itemStyle: {
							normal: {
				                areaColor: '#000000',//第二张地图背景颜色
				                borderColor: '#0084f5ad' //县之间的轮廓颜色
				            },
							emphasis: {
								areaColor: '#32383c59'//鼠标移上去各个省颜色
							}
						}
					},
					series: series
				};
				// 迁徙图
				migrateMap.setOption(tmigrateOption);
			});
		},
		// 定位图
		mapPositioning: function() {
			var qiandongnan = ctx + "/assets/blastStatistics/templates/layer-master/json/guizhou/qiandongnan.json";
			$.get(qiandongnan, function(mapJson) {
				var mapName = "qiandongnan",
					name_title = "黔东南州民爆图",
					subname = '',
					nameColor = '#fff',
					name_fontFamily = '等线',
					subname_fontSize = 15,
					name_fontSize = 18;
				echarts.registerMap(mapName, mapJson);
				
				var data = [
				    {name: '柳川镇', value: 9},
				    {name: '榕江汽车站', value: 12},
				    {name: '凯里学院', value: 12},
				    {name: '榕江县', value: 6},
				    {name: '榕江县1', value: 12},
				    {name: '黎平县1', value: 12},
				    {name: '榕江县2', value: 12},
				    {name: '岑巩县', value: 12},
				    {name: '岑巩县0', value: 12},
				    {name: '岑巩县1', value: 12},
				    {name: '岑巩县2', value: 14},
				    {name: '岑巩县3', value: 8},
				    {name: '岑巩县4', value: 16},
				    {name: '镇远县0', value: 16},
				    {name: '镇远县1', value: 14},
				    {name: '镇远县2', value: 14},
				    {name: '镇远县3', value: 14},
				    {name: '镇远县4', value: 14},
				    {name: '施秉县', value: 10},
				    {name: '施秉县1', value: 10},
				    {name: '黄平县', value: 14},
				    {name: '黄平县1', value: 16},
				    {name: '黄平县2', value: 25},
				    {name: '黄平县3', value: 10},
				    {name: '三穗县', value: 12},
				    {name: '三穗县1', value: 12},
				    {name: '三穗县2', value: 10},
				    {name: '三穗县3', value: 13},
				    {name: '天柱县', value: 16},
				    {name: '天柱县1', value: 20},
				    {name: '天柱县2', value: 18},
				    {name: '天柱县3', value: 14},
				    {name: '台江县', value: 12},
				    {name: '剑河县', value: 20},
				    {name: '剑河县1', value: 12},
				    {name: '剑河县2', value: 12},
				    {name: '剑河县3', value: 12},
				    {name: '锦屏县', value: 12},
				    {name: '锦屏县1', value: 12},
				    {name: '锦屏县2', value: 12},
				    {name: '麻江县', value: 12},
				    {name: '丹寨县', value: 12},
				    {name: '丹寨县1', value: 12},
				    {name: '丹寨县2', value: 12},
				    {name: '雷山县', value: 12},
				    {name: '雷山县1', value: 12},
				    {name: '黎平县', value: 12},
				    {name: '黎平县1', value: 12},
				    {name: '黎平县2', value: 15},
				    {name: '黎平县3', value: 12},
				    {name: '从江县', value: 12},
				    {name: '从江县1', value: 12},
				    {name: '从江县2', value: 12}
				];
				var geoCoordMap = {
					'柳川镇': [108.597987, 26.657547],
					'榕江汽车站': [108.537631, 25.943841], // 榕江汽车站
				  	'凯里学院': [107.898748, 26.530582],
				  	'榕江县': [108.533447, 26.054363],
				    '榕江县1': [108.616235, 26.398685],
				    '黎平县1': [109.19575, 26.191386],
				    '榕江县2': [108.607036, 26.212133],
				    '镇远县': [108.489049,27.232447],
				    '岑巩县': [108.746036,27.335702],
				    '岑巩县0': [108.642551,27.333648],
				    '岑巩县1': [108.444135,27.350657],
				    '岑巩县2': [108.842047,27.401405],
				    '岑巩县3': [108.666697,27.376771],
				    '岑巩县4': [108.674171,27.377798],
				    '镇远县0': [108.464902,27.296672],
				    '镇远县1': [108.468927,27.292563],
				    '镇远县2': [108.339571,27.31208],
				    '镇远县3': [108.608056,27.178984],
				    '镇远县4': [108.436156,27.056538],
				    '施秉县': [108.13835,26.924681],
				    '施秉县1': [108.160772,27.061686],
				    '黄平县': [107.814098,26.869522],
				    '黄平县1': [107.773279,27.00299],
				    '黄平县2': [107.959098,27.000559],
				    '黄平县3': [108.083733,26.814337],
				    '三穗县': [108.558613,26.91128],
				    '三穗县1': [108.660948,26.974661],
				    '三穗县2': [108.899538,26.986509],
				    '三穗县3': [109.009922,26.961266],
				    '天柱县': [109.210568,26.918496],
				    '天柱县1': [109.334174,26.833423],
				    '天柱县2': [109.22494,27.064774],
				    '天柱县3': [109.334174,26.831359],
				    '台江县': [108.337271,26.753446],
				    '剑河县': [108.451104,26.731249],
				    '剑河县1': [108.498822,26.545758],
				    '剑河县2': [108.71959,26.626399],
				    '剑河县3': [108.736262,26.718858],
				    '锦屏县': [108.924835,26.682193],
				    '锦屏县1': [109.169749,26.582467],
				    '锦屏县2': [108.667847,26.744155],
				    '麻江县': [107.754307,26.382751],
				    '丹寨县': [107.914708,26.23092],
				    '丹寨县1': [107.795126,26.199803],
				    '丹寨县2': [107.804324,26.30712],
				    '雷山县': [108.095806,26.382233],
				    '雷山县1': [108.229762,26.441771],
				    '黎平县': [108.838022,26.044095],
				    '黎平县1': [109.042692,26.202397],
				    '黎平县2': [109.290481,26.196173],
				    '黎平县3': [108.913336,26.287945],
				    '从江县': [108.91966,25.759127],
				    '从江县1': [109.122605,25.913658],
				    '从江县2': [108.68452,25.879855]
				    
				};
				
				// 定位
				var myChart = echarts.init(document.getElementById('position_map'));
				
				var max = 480,
				    min = 50; // todo 
				var maxSize4Pin = 100,
				    minSize4Pin = 20;
				
				var convertData = function (data) {
				    var res = [];
				    for (var i = 0; i < data.length; i++) {
				        var geoCoord = geoCoordMap[data[i].name];
				        if (geoCoord) {
				            res.push({
				                name: data[i].name,
				                value: geoCoord.concat(data[i].value)
				            });
				        }
				    }
				    return res;
				};
				
				option = {
				    tooltip : {
				        trigger: 'item'
				    },
				    legend: {
				        orient: 'vertical',
				        y: 'bottom',
				        x:'right',
				        textStyle: {
				            color: '#fff'
				        }
				    },
				    geo: {
				        map: mapName,
				        label: {
				        	normal: {
			                    show: true,
			                    textStyle: {
			                        color: '#fff',//各个省字体颜色
			                        fontSize:8
			                    }
			                },
							emphasis: {
								show: true,
								textStyle: {
			                        color: '#ff0101', //各个省鼠标移上去字体颜色
			                        fontSize: 14
			                    }
							}
				        },
				        roam: false,
				    	itemStyle: {
				    		normal: {
				                areaColor: '#00000000', // 背景颜色
				                borderColor: '#0084f5ad' // 边线颜色
				        	},
				        	emphasis: {
				                areaColor: 'rgba(3,9,3,.6)' // 鼠标移上去时的颜色
				        	}
				    	}
				    },
				    series : [
				        {
				            name: '位置',
				            type: 'effectScatter',
				            coordinateSystem: 'geo',
				            data: convertData(data.sort(function (a, b) {
				                return b.value - a.value;
				            }).slice(0, 50)), // 缩放 0 -6
				            symbolSize: function (val) {
				                return val[2] / 4;
				            }, // 点的大小
				            showEffectOn: 'render',
				            rippleEffect: {
				                brushType: 'stroke'
				            },
				            hoverAnimation: true,
				            itemStyle: {
				                normal: {
				                    color: '#33fc50',
				                    shadowBlur: 1,
				                    shadowColor: '#333'
				                }
				            },
				            zlevel: 1
				        }
				    ]
				};
				myChart.setOption(option);
				/*myChart.on('click', function (params) {
					//params.value == undefined ? alert(params.name) : alert("坐标：" + params.value)
					// 打开详情页
					this.A = params.name;
					if(this.A == "凯里市"){
						window.open('${path}/xingzhengquhua/kailishi.jsp?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="岑巩县"){
						window.open('${path}/terrace/kailishi?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="镇远县"){
						window.open('xingzhengquhua/zhenyuanxian.html?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="施秉县"){
						window.open('xingzhengquhua/shibingxian.html?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="黄平县"){
						window.open('xingzhengquhua/huangpingxian.html?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="三穗县"){
						window.open('xingzhengquhua/sansuixian.html?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="天柱县"){
						window.open('xingzhengquhua/tianzhuxian.html?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="台江县"){
						window.open('xingzhengquhua/taijiangxian.html?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="剑河县"){
						window.open('xingzhengquhua/jianhexian.html?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="锦屏县"){
						window.open('xingzhengquhua/jinpingxian.html?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="麻江县"){
						window.open('xingzhengquhua/majiangxian.html?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="丹寨县"){
						window.open('xingzhengquhua/danzhaixian.html?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="雷山县"){
						window.open('xingzhengquhua/leishanxian.html?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="榕江县"){
						window.open('xingzhengquhua/rongjiangxian.html?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="黎平县"){
						window.open('xingzhengquhua/lipingxian.html?wd=' + encodeURIComponent(params.name));
					}else if(this.A =="从江县"){
						window.open('xingzhengquhua/congjiangxian.html?wd=' + encodeURIComponent(params.name));
					}
				});*/
			});
		}
	};
	
	$(function(){
		page.init(); // 执行代码
	});
	
	e("bigData", {});
});